<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/12/25
 * Time: 20:45
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\common\business\Service;
use app\common\lib\Show;
use app\common\lib\Status;
use think\Exception;

class Package extends Base
{
    public function getPackageListInfo()
    {
        $id = $this->request->param('id', 0, 'intval');
        //获取所有一级栏目
        try {
            $lists = (new \app\common\business\Package())->getListData();
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, $e->getMessage());
        }
        $ret = [];
        //获取第一栏目
        if (!empty($lists)) {
            //根据第一id查询服务项目
            if (!empty($lists[0]['service'])) {
                try {
                    $ret = (new Service())->getServiceByIds(Show::json_decode($lists[0]['service']));
                } catch (\Exception $e) {
                    return Show::json_show(Status::mini_error, $e->getMessage());
                }
            }
        }
        return Show::json_show(Status::mini_normal, "ok", [
            "package" => $lists,
            "service" => $ret
        ]);
    }

    public function getPackageListType()
    {
        $type = $this->request->param('id', 0, 'intval');
        try {
            $service = (new \app\common\business\Package())->getBaseById($type, "id,service");
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, $e->getMessage());
        }
        if (empty($service)) {
            return Show::json_show(Status::mini_error, "数据不存在");
        }
        try {
            $service = (new Service())->getServiceByIds(Show::json_decode($service['service']));
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, "内部错误");
        }
        return Show::json_show(Status::mini_normal, "ok", $service);

    }
}